<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            width: 500px;
            height: 300px;
            background: green;
            margin: 0 auto;
        }
        .left{
            width: 100px;
            height: 300px;
            float: left;
                display: flex;
            flex-direction: column;
            justify-content: space-around;
        }
        .left p{
            padding-left: 10px;
            cursor: pointer;
            color: red;

        }
        .left p img{
            margin-right: 20px;
    vertical-align: middle;
        }
        .left p:hover{
            color: yellow;
        }
        .right{
          float: right;
            width: 350px;
            height: 300px;
            background: palegoldenrod;
        }
        .right span{
            display: inline-block;
            width: 50px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            color:black;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="left">

    </div>
    <div class="right">

    </div>
</div>
</body>
<script src="../lib/jquery/jquery.js"></script>
<script>

    var params={
        navs:[
            {
            type:'场地',
            picOn:'../img/case-type1.png',
            picOff:'../img/case-type1-1.png'

        },
            {
                type:'会务',
                picOn:'../img/case-type2.png',
                picOff:'../img/case-type2-2.png'
            },
            {
                type:'技艺',
                picOn:'../img/case-type3.png',
                picOff:'../img/case-type3-3.png'
            },
            {
                type:'餐饮',
                picOn:'../img/case-type4.png',
                picOff:'../img/case-type4-4.png'
            },
        ],
        items:[
            {item:[1,2,34,4]},
            {item:[2,1,34,4]},
            {item:[3,2,34,4]},
            {item:[4,2,34,4]}
        ]

    };
    class ChoseItem{
        constructor(params){
            this.params=params;
        }

    leftList(){
         var data=this.params.navs;
        data.forEach(function (item,index) {
            let html='';
            html=`<p data-on="${item.picOn}" data-off="${item.picOff}"><img src="${item.picOff}">${item.type}</p>`;
            $('.left').append(html);
        })
    }
    initEvent(){
        $('.left p').eq(0).addClass('active');
        let self=this;
        self.setStatus();
        self.rightSelected(0);
        $('.left').on('click','p',function () {
           $(this).addClass('active').siblings().removeClass('active');
            self.setStatus();
            var index=$(this).index();
            self.rightSelected(index)
        });

    }
    setStatus(){
        $('.left p').each(function (index,item) {
            if(item.className.indexOf('active')>-1){
                $(item).css('color','yellow');
                $(item).find('img').attr('src',$(item).attr('data-on'));
            }else {
                $(item).css('color','red');
                $(item).find('img').attr('src',$(item).attr('data-off'));
            }
        })

    }
    rightSelected(index){
        $('.right').empty();
        this.params.items[index].item.forEach(function (item,index) {
            var html=''
            html=`<span>${item}</span>`;
            $('.right').append(html)
        })
    }
    init(){
        this.leftList();
        this.initEvent();
    }
    }


    const chose=new ChoseItem(params);
    chose.init();

</script>
</html>